Warn about missing [[lib]] and [[bin]] sections
authorAlex Crichton <alex@alexcrichton.com>
Sun, 6 Jul 2014 00:10:23 +0000 (17:10 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 8 Jul 2014 03:59:47 +0000 (20:59 -0700)
Closes #120

src/cargo/util/toml.rs
tests/test_cargo_compile.rs
tests/test_cargo_compile_path_deps.rs

index 788b6d7ffb03cb9172eca06404cd57538151fd2e..d12762ba12e573285df29b5cf52d69b86821472c 100644 (file)
@@ -30,6 +30,10 @@ pub fn to_manifest(contents: &[u8],
         Some(ref toml) => add_unused_keys(&mut manifest, toml, "".to_string()),
         None => {}
     }
+    if manifest.get_targets().len() == 0 {
+        return Err(human(format!("either a [[lib]] or [[bin]] section must \
+                                  be present")))
+    }
     return Ok((manifest, paths));
 
     fn add_unused_keys(m: &mut Manifest, toml: &toml::Value, key: String) {
index 7119ef6b7cde9367032681df097fae238421d7d9..a0e2010ba9836552e5dd7b22df80c97cf737d51b 100644 (file)
@@ -766,3 +766,19 @@ test!(ignore_broken_symlinks {
       process(p.bin("foo")),
       execs().with_stdout("i am foo\n"));
 })
+
+test!(missing_lib_and_bin {
+    let mut p = project("foo");
+    p = p
+        .file("Cargo.toml", r#"
+            [package]
+
+            name = "test"
+            version = "0.0.0"
+            authors = []
+        "#);
+    assert_that(p.cargo_process("cargo-build"),
+                execs().with_status(101)
+                       .with_stderr("either a [[lib]] or [[bin]] section \
+                                     must be present\n"));
+})
index eb02258a3fd49a1249b7878368ae98bffa14a5ba..42a25f10c4c9288534d5f8c57ff44199320bf467 100644 (file)
@@ -493,6 +493,10 @@ test!(error_message_for_missing_manifest {
             [dependencies.bar]
 
             path = "src/bar"
+
+            [[lib]]
+
+            name = "foo"
         "#)
        .file("src/bar/not-a-manifest", "");